package com.jrtc.backend.controller;

import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.LaboratoryReport;
import com.jrtc.base.entity.vo.LaboratoryReportVO;
import com.jrtc.service.LaboratoryReportService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("laboratoryReport")
public class LaboratoryReportController {
    @Resource
    private LaboratoryReportService laboratoryReportService;

    /**
     * 实验室报告列表
     * @param map
     * @return
     */
    @PostMapping("/queryLaboratoryReports")
    public ResultDTO queryLaboratoryReports(@RequestBody Map<String, Object> map) {
        Integer patientId = Integer.valueOf(map.get("patientId").toString());
        List<LaboratoryReportVO> laboratoryReports = laboratoryReportService.queryLaboratoryReports(patientId);
        return ResultDTOBuilder.success(laboratoryReports);
    }

    /**
     * 新增实验室报告
     * @param laboratoryReport
     * @return
     */
    @PostMapping("/insertLaboratoryReports")
    public ResultDTO insertLaboratoryReports(@RequestBody LaboratoryReport laboratoryReport) {
        int i = laboratoryReportService.insertLaboratoryReports(laboratoryReport);
        if (i > 0)
            return ResultDTOBuilder.success(i);
        else
            return ResultDTOBuilder.failureMsg("新增失败");
    }
}
